//
//  CallPhoneTableViewController.m
//  UILbrary
//
//  Created by mac on 17/5/8.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "CallPhoneTableViewController.h"
static NSString *const cellId = @"cellID";

@interface CallPhoneTableViewController ()
@property (nonatomic, strong) NSArray *phoneNumberArr;
@end

@implementation CallPhoneTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellId];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableVie{
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return 1;
    }else{
        return 3;
    }
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    
    if (indexPath.section ==0) {
        cell.textLabel.text = @"下面三种不同的拨打电话方式";
    }else{
        cell.textLabel.text = self.phoneNumberArr[indexPath.row];
    }
    return cell;
}

- (NSArray *)phoneNumberArr{
    if (!_phoneNumberArr) {
        _phoneNumberArr = @[@"13377892977",
                            @"13677892978",
                            @"13877892979"];
    }
    return _phoneNumberArr;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    if (indexPath.section == 1) {
        if (indexPath.row ==0) {
            NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"13377892977"];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        }
        if (indexPath.row == 1) {
            NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"13677892978"];
            UIWebView * callWebview = [[UIWebView alloc] init];
            [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
            [self.view addSubview:callWebview];
        }
        if (indexPath.row == 2) {
            NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"13877892979"];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        }
    }
}


@end
